package cn.wolfcode.wms.web.interceptors;

import cn.wolfcode.wms.domain.Employee;
import cn.wolfcode.wms.util.UserContext;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//登陆拦截器
public class LoginCheckInterceptor extends HandlerInterceptorAdapter{

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {

        //在这里取出session中用户的数据
        Employee emp = UserContext.getCurrentUser();
        //判断是否登陆了,
        if (emp == null) {//表示没有登陆
            //重定向回到登陆界面
            response.sendRedirect("/login.html");
            return false;//不放行
        }


        return true;
    }
}
